package com.example.test15middleware.service;

import com.example.test15middleware.util.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @Author: fxy
 * @Date: 2022/07/21/15:23
 * @Description:
 */
public class RabbitWorker02 {
    private static final String TASK_QUEUE_NAME = "ack_queue";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null);
        DeliverCallback deliverCallback=(consumerTag, delivery)->{
            String receivedMessage = new String(delivery.getBody());
            System.out.println("接收到消息:"+receivedMessage);
        };

        System.out.println("C2 消费者启动等待消费......");
        channel.basicConsume(TASK_QUEUE_NAME,true,deliverCallback,consumerTag->{});
    }
}
